#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<cstring>
using namespace std;
const int N = 1010;
int w[N];
int f[N];
int v[N];
int n, m;
int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
    {
        cin >> v[i] >> w[i];
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = v[i]; j <= m; j++)
        {
            f[j] = max(f[j], f[j - v[i]] + w[i]);
        }
    }
    cout << f[m] << endl;
    memset(f, -0x3f3f3f3f, sizeof(f));
    f[0] = 0;
    for (int i = 1; i <= n; i++)
    {
        for (int j = v[i]; j <= m; j++)
        {

            f[j] = max(f[j], f[j - v[i]] + w[i]);
        }
    }
    if (f[m] > 0)
    {
        cout << f[m] << endl;
    }
    else
    {
        cout << 0 << endl;
    }
    return 0;
}